﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.ComponentModel;

namespace EasyUIDemo1
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            Route route = routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

            Route route3 = routes.MapRoute(
                "Paging", // Route name
                "{controller}/{action}/{pageIndex}", // URL with parameters
                new { controller = "Home", action = "Index", pageIndex = 0 } // Parameter defaults
            );

            int i = routes.Count;


            foreach(Route r in routes)
            {
                object values = r.Defaults;

                foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(values))
                {
                    object obj2 = descriptor.GetValue(values);
                    //this.Add(descriptor.Name, obj2);
                }


                var t = new { controller = "Home", action = "Index", id = UrlParameter.Optional };
                foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(t))
                {
                    object obj3 = descriptor.GetValue(t);
                    //this.Add(descriptor.Name, obj2);
                }

                Route reportRoute = new Route("{locale}/{year}", new MvcRouteHandler());
                reportRoute.Defaults = new RouteValueDictionary() { { "locale", "en-US" }, { "year", DateTime.Now.Year.ToString() } };
                reportRoute.Constraints = new RouteValueDictionary { { "locale", "[a-z]{2}-[a-z]{2}" }, { "year", @"\d{4}" } };
                reportRoute.DataTokens = new RouteValueDictionary { { "format", "short" } };

                //var tt =  { "locale", "en-US" }, { "year", DateTime.Now.Year.ToString() };

                foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(values))
                {
                    object obj3 = descriptor.GetValue(values);
                    //this.Add(descriptor.Name, obj2);
                }
            }

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}